{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Basic example"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "from quickdef import quickdef, quickargs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [],
   "source": [
    "calib = dict(\n",
    "    a=0.1,\n",
    "    b=0.5,\n",
    "    c=0.1\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.1"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@quickdef(calib)\n",
    "def fun(x,y):\n",
    "    return x**2*a + x*b + c\n",
    "\n",
    "# gets translated into\n",
    "# def fun(x,y,calib):\n",
    "#     a = calib['a']\n",
    "#     b = calib['b']\n",
    "#     c = calib['c']\n",
    "#     return x**2*a + x*b + c\n",
    "\n",
    "fun(0,1, calib)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Same with vector arguments"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from collections import OrderedDict as odict\n",
    "\n",
    "calib = odict(\n",
    "    a=0.1,\n",
    "    b=0.5,\n",
    "    c=0.1\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.1"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@quickdef(calib, sub_type='array')\n",
    "def fun(x,y):\n",
    "    return x**2*a + x*b + c\n",
    "\n",
    "# gets translated into\n",
    "# def fun(x,y,calib):\n",
    "#     a = calib[0]\n",
    "#     b = calib[1]\n",
    "#     c = calib[2]\n",
    "#     return x**2*a + x*b + c\n",
    "\n",
    "calib_vec = [e for e in calib.values()]\n",
    "\n",
    "fun(0,1, calib_vec)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Dolo functions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "from collections import OrderedDict\n",
    "import quickdef"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.0"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    " d = OrderedDict(\n",
    "    states = ['α','β'],\n",
    "    controls = ['x', 'y']\n",
    ")\n",
    "\n",
    "\n",
    "@quickargs(d)\n",
    "def fun():\n",
    "    h = α*x + β*y\n",
    "    return h\n",
    "\n",
    "# gets translated into\n",
    "# def fun(states, controls):\n",
    "#    α = states[0]\n",
    "#    β = states[1]\n",
    "#    x = controls[0]\n",
    "#    y = controls[1]\n",
    "#    h = α*x + β*y\n",
    "#    return h\n",
    "\n",
    "\n",
    "import numpy\n",
    "\n",
    "v_states = numpy.array([1.0, 2.0])\n",
    "v_controls = numpy.array([1.0, 1.0])\n",
    "\n",
    "fun(v_states,v_controls)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
